<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>提码管理</title>
    <link rel="stylesheet" href="common/js/file-input/fileinput.css">
    <link rel="stylesheet" href="common/css/switchery/style.css">
    <link rel="stylesheet" href="common/css/bootstrap.css">
    <link rel="stylesheet" href="common/css/font-awesome.min.css">
    <link rel="stylesheet" href="common/css/style.css">
    <link rel="stylesheet" href="common/css/plugin.css">
    <script src="common/js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <!--[if lt IE 9]>
    <script src="common/js/ie/respond.min.js"></script>
    <script src="common/js/ie/html5.js"></script>
    <![endif]-->
</head>
<body onload="initFamaTab()">
<!-- .modal 发送提示 -->
<div class="modal fade operaState in " data-keyboard="false" id="operaState">
    <div class="modal-dialog modal-sm" style="margin-left:-150px;">
        <div class="modal-content">
            <div class="modal-body pop-div-content">
                <p><i class="icon-success"></i></p>

                <p class="tipP">
                    <label id="promptMsg"></label>
                </p>
            </div>
        </div>
    </div>
</div>
<section class="main padder">
    <div class="clearfix">
        <h4><i class="icon-list"></i> 提码列表</h4>
    </div>
    <section class="panel">
        <div class="tab-content">
            <div id="tima" class="tab-pane fade active in">
                <form id="uploadAndSendForm" class="form-horizontal">
                    <div class="form-group">
                        <label class="col-lg-2 control-label text-right">批次名称</label>

                        <div class="col-lg-2">
                            <input type="text" tabindex="1" class="form-control input-small parsley-validated"
                                   data-parsley-required="true" placeholder="批次名称" data-parsley-maxlength="30"
                                   name="name">
                        </div>
                        <label class="col-lg-2 control-label text-right">导出数量</label>

                        <div class="col-lg-2 text-left">
                            <input type="text" tabindex="2" class="form-control input-small parsley-validated"
                                   data-parsley-required="true" data-parsley-type="number" data-parsley-min="1"
                                   placeholder="导出数量" data-parsley-max="10000"
                                   data-parsley-maxlength="30"
                                   name="count" data-parsley-type="alphanum">
                        </div>
                        <label class="col-lg-2 text-left">一次不能超过10000行</label>

                        <div class="col-lg-2">
                            <a href="#" id="uploadAndSend" class="btn btn-primary">
                                下载
                            </a>
                        </div>
                    </div>
                </form>
                <div class="row">
                    <div class="col-lg-12">
                        <section class="panel">
                            <div class="pull-out">
                                <table class="table table-striped m-b-none" data-ride="datatables">
                                    <thead>
                                    <tr>
                                        <!--<th>批次号</th>-->
                                        <th>名称</th>
                                        <th>数量</th>
                                        <th>短信发送</th>
                                        <th>导入时间</th>
                                        <th>状态</th>
                                        <th>发码类型</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </div>
    </section>
</section>


<!-- /.modal 发送提示 -->
<script src="common/js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="common/js/bootstrap.min.js" type="text/javascript"></script>
<script src="common/js/index.js" type="text/javascript"></script>
<!-- 验证 -->
<script src="common/js/parsley/parsley.js" type="text/javascript"></script>
<!-- checkbox -->
<script src="common/js/fuelux/fuelux.js" type="text/javascript"></script>

<!-- datatables -->
<script src="common/js/datatables/jquery.dataTables10.min.js" type="text/javascript"></script>
<script src="static/js/bootbox.min.js" type="text/javascript"></script>
<script>
    var url = window.location.search;
    var actId;
    if (url.lastIndexOf("?") != -1) {
        actId = url.substring(url.lastIndexOf("?") + 1, url.length);

    }
    var famaTable;
    var page = 1
    function initFamaTab() {

        if ($.type(famaTable) != 'object') {
            famaTable = $('#tima').find('table[data-ride="datatables"]').DataTable({
                "ajax": {
                    url: "sendCode/queryPickCodePage?actId=" + actId,
                    type: "post",
                },
                "processing": true,
                "serverSide": true,
                "autoWidth": true,
                "searchDelay": 500,
                "displayStart": parseInt(page) * 10 - 10,
                "pagingType": "full_numbers",
                "pageLength": 10,
                "dom": "<'row'<'col col-lg-6'l><'col col-lg-6'f>r>t<'row'<'col col-lg-6'i><'col col-lg-6'p>>",
                "aaSorting": [[6, "desc"]],//默认排序
                "columns": [
//                    {"data": "id", "name": "id", "width": "100px"},
                    {"data": "batch", "name": "batch", "width": "90px", "sortable": false},
                    {"data": "pickNumber", "name": "pickNumber", "width": "90px", "sortable": false},
                    {"data": "sendSuccessNumber", "name": "sendSuccessNumber", "className": "name", "width": "100px"},
                    {"data": "createtime", "name": "createtime", "width": "180px"},
                    {"data": "status", "name": "status", "width": "170px"},
                    {"data": "sendSmsType", "name": "sendSmsType", "width": "100px"},
                    {"data": null, "width": "170px"}
                ],
                "columnDefs": [
                    {"searchable": false, "targets": [2]},
                    {
                        "targets": 4,
                        "data": "status",
                        "sortable": false,
                        "render": function (data, type, full) {
                            //  batch 00：已删除 01：已提码，未导入联系人  02：已导入联系人，待送码  03：已送码，待发码 04：已发码
                            var statusText;
                            if (data == "01") {
                                statusText = "已提码";
                            }
                            if (data == "02") {
                                statusText = "已导入联系人，待送码";
                            }
                            if (data == "03") {
                                statusText = "已送码，待发码";
                            }
                            if (data == "04") {
                                statusText = "已发码";
                            }
                            return statusText;
                        }
                    },
                    {
                        "targets": 5,
                        "data": "sendSmsType",
                        "sortable": false,
                        "render": function (data, type, full) {
                            var sendSmsTypeText;
                            if (data == "01") {
                                sendSmsTypeText = "下载";
                            }
                            return sendSmsTypeText;
                        }
                    },
                    {
                        "targets": 6,
                        "data": null,
                        "sortable": false,
                        "render": function (data, type, full) {
                            return '<a href="sendCode/download?type=02&id=' + data['id'] + '&name=' + data['batch'] + '"target="_blank" >下载</a>' +
                                    '<a href="timadetail.html?' + data['id'] + '-' + actId + '"target="_blank" >详情</a>'/* +
                             '<a href="javascript:delBatch(\'' + data['id'] + '\')" >删除</a>'*/;
                        }
                    }
                ]
            });
        }
    }
</script>
<script>
    /**
     * 添加发码活动确认按钮
     */
    $("#uploadAndSend").click(function () {
        var formUpLoadAndSend = $("#uploadAndSendForm").parsley();
        if (!formUpLoadAndSend.validate()) {
            return false;
        }
        //获取表单基本元素对象
        var formArray = $("#uploadAndSendForm").serializeArray();
        var formObject = new Object();
        $.each(formArray, function (index) {
            if (formObject[this['name']]) {
                formObject[this['name']] = formObject[this['name']] + "," + this['value'];
            } else {
                formObject[this['name']] = this['value'];
            }
        });
        $.post("sendCode/isExistName", {"actId": actId, "name": formObject["name"]}, function (result) {
            if (result.success) {
                window.location.href = "sendCode/download?type=03&id=" + actId + "&name=" + formObject["name"] + "&count=" + formObject["count"]
                setTimeout(
                        bootbox.confirm("你确定要刷新提码列表吗？", function (result) {
                            if (result) {
                                famaTable.ajax.reload();
                            }
                        }), 3000);

            } else {
                sendMsg(false, result.errorMsg);
            }
        }, 'json');
    })
    ;
</script>
<!--<script>
    function delBatch(id) {
        $.get("sendCode/delBatchById", {"batchId": id}, function (result) {
            if (result.success) {
                sendMsg(true, "删除批次成功");
                window.location.reload();
            } else {
                sendMsg(false, result.errorMsg);
                window.location.reload();
            }
        }, 'json');
    }
</script>-->

</body>
</html>                